var utils = require('../../../../utils/util.js')
var c = require('../../../../utils/config.js')
Page({
    data: {
        orderInfo: [],
        kd_code:"",
        kd_no: "",
        totalNum:0,
        img_url: c.img_url
    },

    onLoad: function (options) {
        this.setData({
            kd_code: options.kd_code,
            kd_no: options.kd_no
        });
        this.getKdInfo();
    },
    getKdInfo: function () {
        var that = this;
        var token = wx.getStorageSync("userinfo").wap_token;
        var data = {
            url: "/wsgoods/ordergoods/findlogistical",
            token: token,
            kd_code: this.data.kd_code,
            kd_no: this.data.kd_no
        };
        utils.request(data).then(function (res) {
            if (res.code == 0) {
                var data = res.data;
                var nums = 0;
                data.order_list.forEach(function (value, index, array) {
                    nums += value.nums;
                });
                that.setData({
                    orderInfo: data,
                    totalNum: nums
                });
            } else {

            }
        });
    }, 
    Confirmed: function (e) {
        var order_no = e.currentTarget.dataset.order_no;
        wx.showModal({
            title: '提示',
            cancelText: '取消',
            confirmText: '确定',
            content: '是否确认收货？',
            success: function (res) {
                if (res.confirm) {
                    var that = this;
                    var token = wx.getStorageSync("userinfo").wap_token;
                    var data = {
                        url: "/v1/ordergoods/finish",
                        token: token,
                        order_no: order_no,
                    };
                    utils.request(data).then(function (res) {
                        if (res.code == 0) {
                            utils.sucMsg("收货成功");
                            setTimeout(function () {
                                wx.navigateBack({
                                    delta:1
                                })
                            }, 1500);
                        } else {

                        }
                    });
                } else if (res.cancel) {

                }
            }
        })
    }
})